package Garagem.Persistencia;

import Negocio.Veiculo;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;


/**
 *
 * @author pablo
 */
public class VeiculoDAO extends BaseDAO<Veiculo> {

    private Connection con;
    
    public void salva(Veiculo veiculo) {

        try {

            con = Conexao.novaConexao();

            String SQL = "INSERT INTO veiculo (descricao) VALUES (?)";
            java.sql.PreparedStatement cmd = con.prepareStatement(SQL);
            cmd.setString(1, veiculo.getDescricao());

            if (cmd.executeUpdate() == 0) {
                throw new RuntimeException("Erro ao salvar o Veiculo");
            }

            con.commit();

        } catch (Exception e) {
            e.printStackTrace();
        }
            try {
                con.rollback();
            } catch (SQLException sqle) {
                System.err.println(sqle);
            }

    }

    
    @Override
    public Veiculo preenche(ResultSet rows) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String tabela() {
        return "veiculo";
    }
    
}
